from selenium import webdriver
from selenium.webdriver.common.by import By

from common.basepage import Basepage
from common.yaml_handler import result
import time

Host = result['Host']


class HomePage(Basepage):
    url = Host + '#/welcome'

    """存放元素定位"""
    # 头像旁边的手机号码
    phone_number = (By.XPATH, "//div[@class='nickName']//span")
    # 定位小区选择框
    click_community = (By.XPATH, "//span[@class='el-input__suffix']")
    # 紫辰蓝山居
    choice_community = (By.XPATH, "//span[contains(text(), '自动化小区')]")
    # 项目管理
    project_management = (By.XPATH, "//span[contains(text(), '项目管理')]")
    # 企业信息
    enterprise_information = (By.XPATH, "//span[contains(text(), '企业信息')]")
    # 组织管理
    organization_management = (By.XPATH, "//span[contains(text(), '组织管理')]")
    # 岗位管理
    post_administration = (By.XPATH, "//span[contains(text(), '岗位管理')]")
    # 角色管理
    role_management = (By.XPATH, "//span[contains(text(), '角色管理')]")

    def load(self):
        self.driver.get(self.url)

    def get_phone_number(self):
        """获取首页头像手机号"""
        # elem = self.driver.find_element(By.XPATH, "//span[contains(text(),'18180573632')]")
        elem = self.driver.find_element(*self.phone_number)
        text = elem.text
        return text

    def get_community(self):
        """点击小区,切换到紫辰蓝山居"""
        # elem1 = self.driver.find_element(*self.click_community)
        # self.driver.execute_script("arguments[0].click()", elem1)
        # time.sleep(1)
        # self.driver.find_element(*self.choice_community).click()
        self.click(self.click_community)
        self.click(self.choice_community)

    def click_project_management(self):
        """点击项目管理-企业信息"""
        # self.driver.find_element(*self.project_management).click()
        # self.driver.find_element(*self.enterprise_information).click()
        self.click(self.project_management).click(self.enterprise_information)
        # self.click(self.enterprise_information)

    def click_organization_management(self):
        """点击进入项目管理-组织管理"""
        self.click(self.project_management).click(self.organization_management)

    def click_post_administration(self):
        """点击进入组织管理"""
        self.click(self.project_management).click(self.post_administration)

    def click_role_management(self):
        """点击进入角色管理"""
        self.click(self.project_management).click(self.role_management)











